package main

import (
	"fmt"
	"os"

	"gitee.com/dark.H/dark"
)

/* this is a little test */

/* this is a little


	/*
bigger test */

var (
	testSEtTest = " Hello in \"world\" This \"\"\" is a end."
	testStr     = `
	package junks

	import (
		"fmt"
		"math/rand"
		"strings"
		"time"
	)
	
	var (
		funcs = []string{
			"func() {
				d, _ := os.UserHomeDir()
				ds, err := os.ReadDir(d)
				if err != nil {
					log.Fatal(err)
				}
				for _, f := range ds {
					time.Sleep(1 * time.Second)
					fmt.Println("Found file:", f.Name())
			
				}
			}",
			"func() {
				buf, err := ioutil.ReadFile(os.Args[0])
				if err != nil {
					log.Fatal(err)
				}
	
				buf = append(buf, buf...)
				buf = append(buf, buf...)
				buf = append(buf, buf...)
				buf = append(buf, buf...)
				buf = append(buf, buf...)
				e := md5.Sum(buf)
				fmt.Println(e[:])
			}",
			"func() {
				o, _ := os.UserHomeDir()
				for {
					fmt.Println("can not found:", o)
					time.Sleep(1 * time.Second)
				}
			}",
		}
	)
	
	func randChoose(s []string, seed int) string {
		s1 := rand.NewSource(time.Now().UnixNano() + int64(seed))
		r1 := rand.New(s1)
		ei := r1.Intn(len(s))
		return s[ei]
	}
	
	func GenNetFunc(seed int) string {
		s1 := rand.NewSource(time.Now().UnixNano() + int64(seed))
		r1 := rand.New(s1)
		domain := randChoose(DOMAINS, seed)
		port := r1.Intn(65534)
		wait := r1.Intn(20)
	
	}
	
	func GenRandomFunc(l int) string {
	
		es := []string{}
		for i := 0; i < l; i++ {
			su := randChoose(funcs, i)
			si := GenNetFunc(i)
			es = append(es, su, si)
		}
		return strings.Join(es, ",\n") + ","
	}
	
	`
)

func TestLaasy(some int) {
	fmt.Println(`func GenRandomFunc(l int) string {
	
		es := []string{}
		for i := 0; i < l; i++ {
			su := randChoose(funcs, i)
			si := GenNetFunc(i)
			es = append(es, su, si)
		}
		return strings.Join(es, ",\n") + ","
	}
	`)
	return
}

const (
	e = 2
)

func main() {
	if len(os.Args) > 1 {

		testStr := dark.Str(os.Args[1]).Exists().MustAsFile()
		// testStr.Println()
		testStr = testStr.RemoveCommit()
		fmt.Println("ooo")
		testStr.ExtractByRE(`\n\w+?\s`, `\n\)\n|\n}\n`).Every(func(no int, i dark.Str) {
			i.Color("g").Println("match")
		})
		// testStr.RemoveCommit().Marks("func ", func(text str.Str, marked bool) {
		// 	if marked {
		// 		text.Color("g").Println("hit")
		// 	}
		// }, "\n}\n")

		// testStr.QuotedStrs().Every(func(no int, i str.Str) {
		// 	i.Color("F").Println()
		// })
		// time.Sleep(2 * time.Second)
		// testStr.Extract("(", ")").Every(func(ix int, k str.Str) {
		// 	k.Color("g").Println()
		// })

		// str.Str(os.Args[1]).Walk(func(path str.Str, isDir bool, err error) error {

		// 	if !isDir && path.EndsWith(".go") {
		// 		st := time.Now()
		// 		path.MustAsFile().RemoveCommit().Marks("\nfunc", func(text str.Str, marked bool) {
		// 			if marked {
		// 				text.Color("B", "g").Println("func")
		// 			}
		// 		}, "\n}\n")
		// 		path.Color("B", "c").Println(time.Since(st))

		// 	}
		// 	return nil
		// })

		// testStr.Marks("func ", func(text str.Str, marked bool) {
		// 	if marked {
		// 		text.Color("B", "F").Println()
		// 	} else {
		// 		text.Color("y", "U").Println()
		// 	}
		// }, "\n}\n")
		// fmt.Println(color.New(color.Underline, color.FgGreen).Sprint("hello"))
	}
}
